package com.test.demo1.controller;

import com.github.pagehelper.PageInfo;
import com.test.demo1.bean.CodeSnippets;
import com.test.demo1.common.PageRequest;
import com.test.demo1.common.ResponseResult;
import com.test.demo1.service.CodeSnippetsService;
import org.springframework.web.bind.annotation.*;
import java.math.BigInteger;
import java.util.List;
/**
 * (CodeSnippets)表控制层
 *
 * @author makejava
 * @since 2025-07-22 21:53:54
 */
@RestController
@RequestMapping("codeSnippets")
public class CodeSnippetsController {
    /**
     * 服务对象
     */

    private final CodeSnippetsService codeSnippetsService;
public CodeSnippetsController(CodeSnippetsService codeSnippetsService){
        this.codeSnippetsService=codeSnippetsService;
}
    /**
     * 全量查询
     *
     * @param codeSnippets 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @PostMapping("queryAll")
    public List<CodeSnippets> queryAll(@RequestBody CodeSnippets codeSnippets) {
        return this.codeSnippetsService.queryAll(codeSnippets);
}
    /**
     * 分页查询
     *
     * @param codeSnippets 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @PostMapping("queryByPage")
    public PageInfo<CodeSnippets> queryByPage(@RequestBody PageRequest<CodeSnippets> codeSnippets) {
        return this.codeSnippetsService.queryByPage(codeSnippets);
}
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseResult<CodeSnippets> queryById(@PathVariable("id") BigInteger id) {
        return ResponseResult.ok(this.codeSnippetsService.queryById(id));
}
    /**
     * 查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @PostMapping("/query")
    public ResponseResult<CodeSnippets> queryOne(@RequestBody CodeSnippets codeSnippets) {
        return ResponseResult.ok(this.codeSnippetsService.selectOne(codeSnippets));
}

    /**
     * 新增数据
     *
     * @param codeSnippets 实体
     * @return 新增结果
     */
    @PostMapping("saveOrUpdate")
    public ResponseResult<CodeSnippets> saveOrUpdate(@RequestBody CodeSnippets codeSnippets) {
    this.codeSnippetsService.saveOrUpdate(codeSnippets);
        return ResponseResult.ok();
}


    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("delete/{id}")
    public ResponseResult<Boolean> deleteById(@PathVariable("id") BigInteger id) {
    this.codeSnippetsService.deleteByPrimaryKey(id);
        return ResponseResult.ok();
}

}

